<template>
	<view class="content">
		<view class="setting" @click="set()">
			<uni-icons type="settings-filled" size=30></uni-icons><br>
			<text style="font-size:10px">设置</text>
		</view>
		<view class="avatar">
			<image :src="(info.avatar===''|info.avatar==='#')?pre:info.avatar"></image>
			<br>
			<text>{{info.role}}</text>
		</view>
		<view class="selfinfo">
			<uni-table emptyText="暂无更多数据">
				<uni-tr>
					<uni-th width="100px" ></uni-th>
					<uni-th></uni-th>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">姓名</uni-td>
					<uni-td  align="center">{{info.name}}</uni-td>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">性别</uni-td>
					<uni-td align="center">{{info.sex}}</uni-td>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">籍贯</uni-td>
					<uni-td align="center">{{info.nativePlace}}</uni-td>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">身份证号</uni-td>
					<uni-td align="center">{{info.idNumber}}</uni-td>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">家庭地址</uni-td>
					<uni-td align="center">{{info.address}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
	</view>
	
</template>

<script>
	import {getGender, getType} from '@/utils/mapUtil.js'
	export default{
		onLoad() {
			let userInfo = uni.getStorageSync('userInfo')
			this.info.name = userInfo.name
			this.info.sex = getGender(userInfo.gender)
			this.info.nativePlace = userInfo.address
			this.info.address = userInfo.location
			this.info.idNumber = userInfo.idCard
			this.info.role = getType(userInfo.type)
			this.info.avatar = userInfo.avatar
		},
		
		onPullDownRefresh() {
			let userInfo = uni.getStorageSync('userInfo')
			
			this.info.name = userInfo.name
			this.info.sex = getGender(userInfo.gender)
			this.info.nativePlace = userInfo.address
			this.info.address = userInfo.location
			this.info.idNumber = userInfo.idCard
			this.info.role = getType(userInfo.type)
			this.info.avatar = userInfo.avatar
			uni.stopPullDownRefresh()
		},
		data(){
			return{
				pre:'/static/mine/image/avatar.jpeg',
				info:{
					name:'胡图图',
					sex:'男',
					nativePlace:'地球',
					idNumber:'422622200303212124',
					address:'翻斗大街翻斗花园二号楼1001室',
					role:'学生',
					avatar: ''
				}
			}
		},
		methods:{
			set(){
				uni.navigateTo({
					url: '/pages/mine/setting',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLaunch(){
			uni.request({
				url: 'http://127.0.0.1:4523/m1/1494405-0-default/api/1/my/updateInfo',
				method: 'GET',
				data: {},
				success: res => {
					this.info = res.data
				},
				fail: () => {},
				complete: () => {}
			});
		}
	}
</script>

<style scoped>
	.setting{
		float:right;
		padding:10px;
		text-align: center;
	}
	.avatar{
		width: 150px;
		height: 100px;
		padding: 50px 250rpx;
		margin: auto;
		text-align: center;
	}
	image{
		width: 90px;
		height: 90px;
		border-radius: 50px;
	}
	.selfinfo{
		width:350px;
		margin: auto;
	}
</style>